package com.mangguo.tingjian.user.mapper;

import com.mangguo.tingjian.user.dto.CountResult;
import com.mangguo.tingjian.user.entity.DwUserLiveApp;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * app活跃用户表 Mapper 接口
 * </p>
 *
 * @author auto
 * @since 2019-11-23
 */
@Mapper
public interface DwUserLiveAppMapper extends BaseMapper<DwUserLiveApp> {
    @Select("select count(DISTINCT imei) as count from dw_user_live_app where mdate >= #{start} and mdate <= #{end} ")
    Long countUniqueImeiBetweenDate(@Param("start")Integer start,
                                       @Param("end") Integer end);

    @Select("select count(DISTINCT imei) as count,mYear,mMonth from dw_user_live_app group by mYear,mMonth")
    List<CountResult> countUniqueImeiByMonth();

    @Select("select  count(DISTINCT imei) as count,mYear,mMonth from visual.dw_user_live_app where mdate >= #{start} and mdate <= #{end} group by mYear,mMonth")
    List<CountResult> countUniqueImeiByMonthBetweenDate(@Param("start")Integer start,
                                                        @Param("end") Integer end);

    @Select("select count(DISTINCT imei) as count,mYear,mWeek,mMonth from dw_user_live_app group by mYear,mWeek,mMonth")
    List<CountResult> countUniqueImeiByWeek();

    @Select("select count(DISTINCT imei) as count,mYear,mWeek,mMonth from dw_user_live_app where mdate >= #{start} and mdate <= #{end} group by mYear,mWeek,mMonth")
    List<CountResult> countUniqueImeiByWeekBetweenDate(@Param("start")Integer start,
                                                       @Param("end") Integer end);

    @Select("select count(DISTINCT imei) as count,mDate from dw_user_live_app group by mDate")
    List<CountResult> countUniqueImeiByDate();

    @Select("select count(DISTINCT imei) as count,mDate from dw_user_live_app where mdate >= #{start} and mdate <= #{end} group by mDate")
    List<CountResult> countUniqueImeiByDateBetweenDate(@Param("start")Integer start,
                                                       @Param("end") Integer end);
}
